import requests										#导入requests模块
from lxml import etree								#导入lxml
headers = {
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36",
    "Referer": "https://movie.douban.com/",
}												# 请求头设置
url = "https://movie.douban.com/cinema/nowplaying/chongqing/"	#定义请求URL
rep = requests.get(url, headers=headers)					#发起请求
text = rep.text										#返回Unicode型数据
html = etree.HTML(text)								# 转换成html格式
ul = html.xpath("//ul[@class='lists']")[0]					# 找到子孙节点ul标签
lis = ul.xpath("./li")									# 当前ul下的所有li标签
movies = []										#空列表
for li in lis:											# 循环每个li标签
    title = li.xpath("@data-title")[0]						# 直接@li标签的属性获取值
    score = li.xpath("@data-score")[0]
    region = li.xpath("@data-region")[0]
    actors = li.xpath("@data-actors")[0]
    director = li.xpath("@data-director")[0]
    liimg = li.xpath(".//img/@src")
    movie = {
        "title": title,
        "score": score,
        "region": region,
        "actors": actors,
        "director": director,
        "liimg": liimg,
    }											#字典数据
    movies.append(movie)							#添加到列表
print(movies)										#输出结果
